

exp2 <- read_csv("Data/Conjoint - Statecraft_competence - 2_April 22, 2021_22.csv")



names(exp2)[1] <- "UK_fav"
names(exp2)[2] <- "Canada_fav"
names(exp2)[3] <- "India_fav"
names(exp2)[4] <- "China_fav"
names(exp2)[5] <- "Egypt_fav"
names(exp2)[6] <- "SoAf_fav"
names(exp2)[7] <- "Russia_fav"
names(exp2)[8] <- "NoKor_fav"
names(exp2)[9] <- "Argentina_fav"
names(exp2)[10] <- "Pakistan_fav"
names(exp2)[11] <- "Iran_fav"
names(exp2)[12] <- "Syria_fav"
names(exp2)[13] <- "Cuba_fav"
names(exp2)[14] <- "Sudan_fav"
names(exp2)[15] <- "Mexico_fav"
names(exp2)[16] <- "Colombia_fav"
names(exp2)[17] <- "Myanmar_fav"
names(exp2)[18] <- "Afghanistan_fav"
names(exp2)[19] <- "Morocco_fav"

exp2 <- exp2 %>%
  mutate(party = ifelse(Q52 == "Neither", "TrueInd", 
                        ifelse(Q52 == "Lean Republican", "IndRep",
                               ifelse(Q52 == "Lean Democrat", "IndDem", NA))))
         
exp2$party[exp2$Q50 == "Not very strong"] <- "WeakRep"
exp2$party[exp2$Q50 == "Very strong"] <- "StrongRep"
exp2$party[exp2$Q48 == "Not very strong"] <- "WeakDem"
exp2$party[exp2$Q48 == "Very strong"] <- "StrongDem"

exp2$Q50 <- exp2$Q52 <- exp2$Q48 <- exp2$Q46 <- NULL


exp2 <- exp2 %>%
  rename(urban_rural = Q118)

exp2 <- exp2 %>%
  rename(support_terror = '1_Q181_4',
         support_dem = '1_Q147_4',
         USint_terror = '1_Q181_5',
         USint_dem = '1_Q147_5',
         costly_terror = '1_Q181_6',
         costly_dem = '1_Q147_6',
         effective_terror = '1_Q181_7',
         effective_dem = '1_Q147_10',
         strength_terror = '1_Q181_10',
         stength_dem = '1_Q147_11',
         message_terror = '1_Q181_11',
         message_dem = '1_Q147_12')
                                                    
exp2 <- exp2 %>%
  mutate(DV_support = ifelse(badbehavior1 == "terror", support_terror, 
                             ifelse(badbehavior1 == "stopdemocracy", support_dem, NA)),
         DV_interests = ifelse(badbehavior1 == "terror", USint_terror, 
                             ifelse(badbehavior1 == "stopdemocracy", USint_dem, NA)),
         DV_costly = ifelse(badbehavior1 == "terror", costly_terror, 
                             ifelse(badbehavior1 == "stopdemocracy", costly_dem, NA)),
         DV_effective = ifelse(badbehavior1 == "terror", effective_terror, 
                             ifelse(badbehavior1 == "stopdemocracy", effective_dem, NA)),
         DV_strength = ifelse(badbehavior1 == "terror", strength_terror, 
                             ifelse(badbehavior1 == "stopdemocracy", stength_dem, NA)),
         DV_message = ifelse(badbehavior1 == "terror", message_terror, 
                             ifelse(badbehavior1 == "stopdemocracy", message_dem, NA))
         )

# Final DVs
exp2 <- exp2 %>%
  mutate(
DV_support = as.numeric(DV_support),
DV_interests = as.numeric(DV_interests),
DV_costly = as.numeric(DV_costly),
DV_effective = as.numeric(DV_effective),
DV_strength = as.numeric(DV_strength),
DV_message = as.numeric(DV_message)
  )

exp2 <- exp2 %>%
  select(-support_terror, -support_dem, -USint_terror, -USint_dem, -costly_terror,
         -costly_dem, -effective_terror, -effective_dem, -strength_terror,
         -stength_dem, -message_terror, -message_dem)


exp2 <- exp2 %>%
  mutate(
    Effect = ifelse(c1_attrib1_name == "Effect on economy", word(c1_attrib1, 1), 
                    ifelse(c1_attrib2_name == "Effect on economy", word(c1_attrib2, 1),
                           ifelse(c1_attrib3_name == "Effect on economy", word(c1_attrib3, 1),
                                  ifelse(c1_attrib4_name == "Effect on economy", word(c1_attrib4, 1), NA
                    )))),
    Effect = as.numeric(str_remove(Effect, "[$]"))
  )

exp2 <- exp2 %>%
  mutate(
    Inaction = ifelse(c1_attrib1_name == "Outcome of Inaction", word(c1_attrib1, -1), 
                    ifelse(c1_attrib2_name == "Outcome of Inaction", word(c1_attrib2, -1),
                         ifelse(c1_attrib3_name == "Outcome of Inaction", word(c1_attrib3, -1),
                                ifelse(c1_attrib4_name == "Outcome of Inaction", word(c1_attrib4, -1), NA
                    )))),
  Inaction = ifelse(Inaction == "continue", "Continue", 
                    ifelse(Inaction == "future", "TickingClock", NA))
)


exp2 <- exp2 %>%
  mutate( 
    Rationale = ifelse(c1_attrib1_name == "US Rationale for Proposal", word(c1_attrib1, 5),
                       ifelse(c1_attrib2_name == "US Rationale for Proposal", word(c1_attrib2, 5),
                              ifelse(c1_attrib3_name == "US Rationale for Proposal", word(c1_attrib3, 5),
                                     ifelse(c1_attrib4_name == "US Rationale for Proposal", word(c1_attrib4, 5), NA
                    )))),
    Rationale = ifelse(Rationale == "enduring", "LongRun", 
                       ifelse(Rationale == "immediate", "Immediate", NA))
  )



exp2 <- exp2 %>%
  mutate( 
    Author = ifelse(c1_attrib1_name == "Proposal Author", word(c1_attrib1, -1),
                       ifelse(c1_attrib2_name == "Proposal Author", word(c1_attrib2, -1),
                              ifelse(c1_attrib3_name == "Proposal Author", word(c1_attrib3, -1),
                                     ifelse(c1_attrib4_name == "Proposal Author", word(c1_attrib4, -1), NA
                                     )))),
    Author = ifelse(Author == "appointee", "Appointee_only",
                    ifelse(Author == "donor", "Appointee_donor",
                           ifelse(Author == "service", "Professional",
                                  ifelse(Author == "Cuba" | Author == "Iran" | Author == "Sudan" | Author == "Syria", "Professional_expert", NA
                                     ))))
  )


exp2 <- exp2 %>%
  select(-c1_attrib1_name, -c1_attrib2_name, -c1_attrib3_name, -c1_attrib4_name, 
         -c1_attrib1, -c1_attrib2, -c1_attrib3, -c1_attrib4)



exp2 <- exp2 %>%
  mutate(Background = ifelse(countrybackground == "has a long history of repressing pro-democracy activists" | 
                               countrybackground == "has a long history of sponsoring terrorist activity", "LongHistory",
                             ifelse(countrybackground == "recently shifted policy, leading to a surge in funding for terrorist groups" |
                                      countrybackground == "recently shifted policy, leading to a surge in repression of pro-democracy activists", "RecentShift", NA)))


# Code policy types
exp2 <- exp2 %>%
  mutate( 
     Policy = ifelse(policy == "Financial sanctions prohibiting certain international payments to and from", "Sanctions", 
                     ifelse(policy == "Financial inducements facilitating investment in", "Inducements", NA))
  )


exp2 <- exp2 %>%
  select(-policy, -policy2, -policy3, -countrybackground, -outcome, -number)



# Code prior support
exp2 <- exp2 %>%
  mutate(
    Prior = ifelse(country1 == "Cuba", Cuba_fav, 
                   ifelse(country1 == "Iran", Iran_fav,
                          ifelse(country1 == "Sudan", Sudan_fav, 
                                 ifelse(country1 == "Syria", Syria_fav, NA))))
  )


# Delete unneeded rows
exp2 = exp2[-c(1, 2),]


